<?php
 class Database {
 	
 	protected static $_instance;
 	protected $_conn;

 	
 	private function __construct() {
 		$this->_conn = @new mysqli('localhost', 'dev', 'password', 'glcci');
 		if($this->_conn->connect_errno) {
 			// should try to grab symfony routing and direct user to module/action that displays DB down message.
 			die('Database down. Contact the administrator at morganney@gmail.com');
 		}
 	}
 	
  public function __destruct() {
 		if(!$this->_conn->connect_errno) $this->_conn->close();
 	}
 	
 	private function __clone() {}

 	public static function getInstance() {
 		if(!(self::$_instance instanceof self)) {
 			self::$_instance = new self();
 		}
 		return self::$_instance;
 	}
 	
 	/**
 	 * 
 	 * Returns the database connection for use directly by a DAO
 	 * NOTE:  Note sure if returning the connection by reference (&) is necessary
 	 * since it represents an object (created with the 'new' keyword).  In 
 	 * PHP 5 object variables should only hold references. Right?
 	 */
 	public function getConnection() {
 		return $this->_conn;
 	}
 }
 